package com.cssw.fyzb.busi.api.video;

import com.cssw.fyzb.busi.service.video.VideoStatService;
import com.cssw.fyzb.core.model.dodb.CmfUserMusic;
import com.ydn.appserver.Action;
import com.ydn.appserver.Request;
import com.ydn.appserver.Response;
import com.ydn.appserver.annotations.Function;
import com.ydn.appserver.annotations.Parameter;
import com.ydn.appserver.annotations.Type;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.Date;

/**
 * @description:
 * @author: zzf
 * @time: 2021/1/19 20:21
 */
@Function(description = "同步Video至es", parameters = {
        @Parameter(name = "videoId", type = Type.Integer, description = "视频标识", required = true),
        @Parameter(name = "type", type = Type.String, description = "为all时同步所有", required = true)
})
@Component
public class SyncVideoEs implements Action {

    @Autowired
    private VideoStatService videoStatService;

    private static final Logger logger = LoggerFactory.getLogger(SyncVideoEs.class);


    @Override
    public Response execute(Request request) throws Exception {
        Long videoId = request.getLong("videoId");
        String type = request.getString("type");
        try {
            videoStatService.syncToEs(videoId, type);
            return Response.success();
        } catch (Exception e) {
            logger.info("", e);
            return Response.fail("操作异常");
        }
    }
}

